package com.msb.dongbao.common.base.result;

import com.msb.dongbao.common.base.enums.StateCodeEnum;
import lombok.Builder;
import lombok.Data;

import java.io.Serializable;

/**
 * @author: mayu
 * @date: 2021年05月27日 9:13
 * 统一返回结果包装类
 */
@Data
@Builder
public class ResultWrapper<T> implements Serializable {
    //状态码
    private int code;
    //提示信息
    private String msg;
    //数据
    private T data;

    /**
     * 返回成功的包装
     *
     * @return com.msb.dongbao.common.base.result.ResultWrapper.ResultWrapperBuilder
     */
    public static ResultWrapper.ResultWrapperBuilder getSuccessBuilder() {
        return ResultWrapper.builder().code(StateCodeEnum.SUCCESS.getCode()).msg(StateCodeEnum.SUCCESS.getMsg());
    }

    /**
     * 返回失败的包装
     *
     * @return com.msb.dongbao.common.base.result.ResultWrapper.ResultWrapperBuilder
     */
    public static ResultWrapper.ResultWrapperBuilder getFailBuilder() {
        return ResultWrapper.builder().code(StateCodeEnum.FAIL.getCode()).msg(StateCodeEnum.FAIL.getMsg());
    }
}
